package spring.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import spring.dao.UserDao;
import spring.domain.User;
import spring.domain.UserLog;

import java.util.List;


public class UserService {

    public User queryByNameAndPassword(String name, String password) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        UserDao userDao = (UserDao) ac.getBean("userDao");
        User user = userDao.queryByNameAndPassword(name, password);
        return user;
    }

    public List<UserLog> queryAllLogs(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        UserDao userDao = (UserDao) ac.getBean("userDao");
        List<UserLog> userLog = userDao.queryAllLogs();
        return userLog;
    }

    public void insert(UserLog userLog){
        ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        UserDao userDao = (UserDao) ac.getBean("userDao");
        userDao.insertLog(userLog);
    }

}
